﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using bookMaster.AssetSystem.Entities;
using bookMaster.AssetSystem.Data;

#endregion

namespace bookMaster.AssetSystem.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="UsuariosRecursosProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class UsuariosRecursosProviderBaseCore : EntityProviderBase<bookMaster.AssetSystem.Entities.UsuariosRecursos, bookMaster.AssetSystem.Entities.UsuariosRecursosKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, bookMaster.AssetSystem.Entities.UsuariosRecursosKey key)
		{
			return Delete(transactionManager, key.IdUsuario, key.IdRecurso);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_idUsuario">. Primary Key.</param>
		/// <param name="_idRecurso">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(string _idUsuario, int _idRecurso)
		{
			return Delete(null, _idUsuario, _idRecurso);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_idUsuario">. Primary Key.</param>
		/// <param name="_idRecurso">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, string _idUsuario, int _idRecurso);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_UsuarioRecursos_Recursos key.
		///		FK_UsuarioRecursos_Recursos Description: 
		/// </summary>
		/// <param name="_idRecurso"></param>
		/// <returns>Returns a typed collection of bookMaster.AssetSystem.Entities.UsuariosRecursos objects.</returns>
		public TList<UsuariosRecursos> GetByIdRecurso(int _idRecurso)
		{
			int count = -1;
			return GetByIdRecurso(_idRecurso, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_UsuarioRecursos_Recursos key.
		///		FK_UsuarioRecursos_Recursos Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_idRecurso"></param>
		/// <returns>Returns a typed collection of bookMaster.AssetSystem.Entities.UsuariosRecursos objects.</returns>
		/// <remarks></remarks>
		public TList<UsuariosRecursos> GetByIdRecurso(TransactionManager transactionManager, int _idRecurso)
		{
			int count = -1;
			return GetByIdRecurso(transactionManager, _idRecurso, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_UsuarioRecursos_Recursos key.
		///		FK_UsuarioRecursos_Recursos Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_idRecurso"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of bookMaster.AssetSystem.Entities.UsuariosRecursos objects.</returns>
		public TList<UsuariosRecursos> GetByIdRecurso(TransactionManager transactionManager, int _idRecurso, int start, int pageLength)
		{
			int count = -1;
			return GetByIdRecurso(transactionManager, _idRecurso, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_UsuarioRecursos_Recursos key.
		///		fkUsuarioRecursosRecursos Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_idRecurso"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of bookMaster.AssetSystem.Entities.UsuariosRecursos objects.</returns>
		public TList<UsuariosRecursos> GetByIdRecurso(int _idRecurso, int start, int pageLength)
		{
			int count =  -1;
			return GetByIdRecurso(null, _idRecurso, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_UsuarioRecursos_Recursos key.
		///		fkUsuarioRecursosRecursos Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_idRecurso"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of bookMaster.AssetSystem.Entities.UsuariosRecursos objects.</returns>
		public TList<UsuariosRecursos> GetByIdRecurso(int _idRecurso, int start, int pageLength,out int count)
		{
			return GetByIdRecurso(null, _idRecurso, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_UsuarioRecursos_Recursos key.
		///		FK_UsuarioRecursos_Recursos Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_idRecurso"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of bookMaster.AssetSystem.Entities.UsuariosRecursos objects.</returns>
		public abstract TList<UsuariosRecursos> GetByIdRecurso(TransactionManager transactionManager, int _idRecurso, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_UsuarioRecursos_Usuarios key.
		///		FK_UsuarioRecursos_Usuarios Description: 
		/// </summary>
		/// <param name="_idUsuario"></param>
		/// <returns>Returns a typed collection of bookMaster.AssetSystem.Entities.UsuariosRecursos objects.</returns>
		public TList<UsuariosRecursos> GetByIdUsuario(string _idUsuario)
		{
			int count = -1;
			return GetByIdUsuario(_idUsuario, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_UsuarioRecursos_Usuarios key.
		///		FK_UsuarioRecursos_Usuarios Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_idUsuario"></param>
		/// <returns>Returns a typed collection of bookMaster.AssetSystem.Entities.UsuariosRecursos objects.</returns>
		/// <remarks></remarks>
		public TList<UsuariosRecursos> GetByIdUsuario(TransactionManager transactionManager, string _idUsuario)
		{
			int count = -1;
			return GetByIdUsuario(transactionManager, _idUsuario, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_UsuarioRecursos_Usuarios key.
		///		FK_UsuarioRecursos_Usuarios Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_idUsuario"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of bookMaster.AssetSystem.Entities.UsuariosRecursos objects.</returns>
		public TList<UsuariosRecursos> GetByIdUsuario(TransactionManager transactionManager, string _idUsuario, int start, int pageLength)
		{
			int count = -1;
			return GetByIdUsuario(transactionManager, _idUsuario, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_UsuarioRecursos_Usuarios key.
		///		fkUsuarioRecursosUsuarios Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_idUsuario"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of bookMaster.AssetSystem.Entities.UsuariosRecursos objects.</returns>
		public TList<UsuariosRecursos> GetByIdUsuario(string _idUsuario, int start, int pageLength)
		{
			int count =  -1;
			return GetByIdUsuario(null, _idUsuario, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_UsuarioRecursos_Usuarios key.
		///		fkUsuarioRecursosUsuarios Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_idUsuario"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of bookMaster.AssetSystem.Entities.UsuariosRecursos objects.</returns>
		public TList<UsuariosRecursos> GetByIdUsuario(string _idUsuario, int start, int pageLength,out int count)
		{
			return GetByIdUsuario(null, _idUsuario, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_UsuarioRecursos_Usuarios key.
		///		FK_UsuarioRecursos_Usuarios Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_idUsuario"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of bookMaster.AssetSystem.Entities.UsuariosRecursos objects.</returns>
		public abstract TList<UsuariosRecursos> GetByIdUsuario(TransactionManager transactionManager, string _idUsuario, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override bookMaster.AssetSystem.Entities.UsuariosRecursos Get(TransactionManager transactionManager, bookMaster.AssetSystem.Entities.UsuariosRecursosKey key, int start, int pageLength)
		{
			return GetByIdUsuarioIdRecurso(transactionManager, key.IdUsuario, key.IdRecurso, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_UsuarioRecursos index.
		/// </summary>
		/// <param name="_idUsuario"></param>
		/// <param name="_idRecurso"></param>
		/// <returns>Returns an instance of the <see cref="bookMaster.AssetSystem.Entities.UsuariosRecursos"/> class.</returns>
		public bookMaster.AssetSystem.Entities.UsuariosRecursos GetByIdUsuarioIdRecurso(string _idUsuario, int _idRecurso)
		{
			int count = -1;
			return GetByIdUsuarioIdRecurso(null,_idUsuario, _idRecurso, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_UsuarioRecursos index.
		/// </summary>
		/// <param name="_idUsuario"></param>
		/// <param name="_idRecurso"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="bookMaster.AssetSystem.Entities.UsuariosRecursos"/> class.</returns>
		public bookMaster.AssetSystem.Entities.UsuariosRecursos GetByIdUsuarioIdRecurso(string _idUsuario, int _idRecurso, int start, int pageLength)
		{
			int count = -1;
			return GetByIdUsuarioIdRecurso(null, _idUsuario, _idRecurso, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_UsuarioRecursos index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_idUsuario"></param>
		/// <param name="_idRecurso"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="bookMaster.AssetSystem.Entities.UsuariosRecursos"/> class.</returns>
		public bookMaster.AssetSystem.Entities.UsuariosRecursos GetByIdUsuarioIdRecurso(TransactionManager transactionManager, string _idUsuario, int _idRecurso)
		{
			int count = -1;
			return GetByIdUsuarioIdRecurso(transactionManager, _idUsuario, _idRecurso, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_UsuarioRecursos index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_idUsuario"></param>
		/// <param name="_idRecurso"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="bookMaster.AssetSystem.Entities.UsuariosRecursos"/> class.</returns>
		public bookMaster.AssetSystem.Entities.UsuariosRecursos GetByIdUsuarioIdRecurso(TransactionManager transactionManager, string _idUsuario, int _idRecurso, int start, int pageLength)
		{
			int count = -1;
			return GetByIdUsuarioIdRecurso(transactionManager, _idUsuario, _idRecurso, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_UsuarioRecursos index.
		/// </summary>
		/// <param name="_idUsuario"></param>
		/// <param name="_idRecurso"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="bookMaster.AssetSystem.Entities.UsuariosRecursos"/> class.</returns>
		public bookMaster.AssetSystem.Entities.UsuariosRecursos GetByIdUsuarioIdRecurso(string _idUsuario, int _idRecurso, int start, int pageLength, out int count)
		{
			return GetByIdUsuarioIdRecurso(null, _idUsuario, _idRecurso, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_UsuarioRecursos index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_idUsuario"></param>
		/// <param name="_idRecurso"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="bookMaster.AssetSystem.Entities.UsuariosRecursos"/> class.</returns>
		public abstract bookMaster.AssetSystem.Entities.UsuariosRecursos GetByIdUsuarioIdRecurso(TransactionManager transactionManager, string _idUsuario, int _idRecurso, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;UsuariosRecursos&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;UsuariosRecursos&gt;"/></returns>
		public static TList<UsuariosRecursos> Fill(IDataReader reader, TList<UsuariosRecursos> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				bookMaster.AssetSystem.Entities.UsuariosRecursos c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("UsuariosRecursos")
					.Append("|").Append((string)reader[((int)UsuariosRecursosColumn.IdUsuario - 1)])
					.Append("|").Append((int)reader[((int)UsuariosRecursosColumn.IdRecurso - 1)]).ToString();
					c = EntityManager.LocateOrCreate<UsuariosRecursos>(
					key.ToString(), // EntityTrackingKey
					"UsuariosRecursos",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new bookMaster.AssetSystem.Entities.UsuariosRecursos();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.IdUsuario = (string)reader[((int)UsuariosRecursosColumn.IdUsuario - 1)];
					c.OriginalIdUsuario = c.IdUsuario;
					c.IdRecurso = (int)reader[((int)UsuariosRecursosColumn.IdRecurso - 1)];
					c.OriginalIdRecurso = c.IdRecurso;
					c.PermiteAcceso = (short)reader[((int)UsuariosRecursosColumn.PermiteAcceso - 1)];
					c.PermiteEscritura = (short)reader[((int)UsuariosRecursosColumn.PermiteEscritura - 1)];
					c.PermisosEspeciales = (short)reader[((int)UsuariosRecursosColumn.PermisosEspeciales - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="bookMaster.AssetSystem.Entities.UsuariosRecursos"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="bookMaster.AssetSystem.Entities.UsuariosRecursos"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, bookMaster.AssetSystem.Entities.UsuariosRecursos entity)
		{
			if (!reader.Read()) return;
			
			entity.IdUsuario = (string)reader[((int)UsuariosRecursosColumn.IdUsuario - 1)];
			entity.OriginalIdUsuario = (string)reader["IdUsuario"];
			entity.IdRecurso = (int)reader[((int)UsuariosRecursosColumn.IdRecurso - 1)];
			entity.OriginalIdRecurso = (int)reader["IdRecurso"];
			entity.PermiteAcceso = (short)reader[((int)UsuariosRecursosColumn.PermiteAcceso - 1)];
			entity.PermiteEscritura = (short)reader[((int)UsuariosRecursosColumn.PermiteEscritura - 1)];
			entity.PermisosEspeciales = (short)reader[((int)UsuariosRecursosColumn.PermisosEspeciales - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="bookMaster.AssetSystem.Entities.UsuariosRecursos"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="bookMaster.AssetSystem.Entities.UsuariosRecursos"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, bookMaster.AssetSystem.Entities.UsuariosRecursos entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.IdUsuario = (string)dataRow["IdUsuario"];
			entity.OriginalIdUsuario = (string)dataRow["IdUsuario"];
			entity.IdRecurso = (int)dataRow["IdRecurso"];
			entity.OriginalIdRecurso = (int)dataRow["IdRecurso"];
			entity.PermiteAcceso = (short)dataRow["PermiteAcceso"];
			entity.PermiteEscritura = (short)dataRow["PermiteEscritura"];
			entity.PermisosEspeciales = (short)dataRow["PermisosEspeciales"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="bookMaster.AssetSystem.Entities.UsuariosRecursos"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">bookMaster.AssetSystem.Entities.UsuariosRecursos Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, bookMaster.AssetSystem.Entities.UsuariosRecursos entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region IdRecursoSource	
			if (CanDeepLoad(entity, "Recursos|IdRecursoSource", deepLoadType, innerList) 
				&& entity.IdRecursoSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.IdRecurso;
				Recursos tmpEntity = EntityManager.LocateEntity<Recursos>(EntityLocator.ConstructKeyFromPkItems(typeof(Recursos), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.IdRecursoSource = tmpEntity;
				else
					entity.IdRecursoSource = DataRepository.RecursosProvider.GetByIdRecurso(transactionManager, entity.IdRecurso);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'IdRecursoSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.IdRecursoSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.RecursosProvider.DeepLoad(transactionManager, entity.IdRecursoSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion IdRecursoSource

			#region IdUsuarioSource	
			if (CanDeepLoad(entity, "Usuarios|IdUsuarioSource", deepLoadType, innerList) 
				&& entity.IdUsuarioSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.IdUsuario;
				Usuarios tmpEntity = EntityManager.LocateEntity<Usuarios>(EntityLocator.ConstructKeyFromPkItems(typeof(Usuarios), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.IdUsuarioSource = tmpEntity;
				else
					entity.IdUsuarioSource = DataRepository.UsuariosProvider.GetByIdUsuario(transactionManager, entity.IdUsuario);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'IdUsuarioSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.IdUsuarioSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.UsuariosProvider.DeepLoad(transactionManager, entity.IdUsuarioSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion IdUsuarioSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the bookMaster.AssetSystem.Entities.UsuariosRecursos object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">bookMaster.AssetSystem.Entities.UsuariosRecursos instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">bookMaster.AssetSystem.Entities.UsuariosRecursos Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, bookMaster.AssetSystem.Entities.UsuariosRecursos entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region IdRecursoSource
			if (CanDeepSave(entity, "Recursos|IdRecursoSource", deepSaveType, innerList) 
				&& entity.IdRecursoSource != null)
			{
				DataRepository.RecursosProvider.Save(transactionManager, entity.IdRecursoSource);
				entity.IdRecurso = entity.IdRecursoSource.IdRecurso;
			}
			#endregion 
			
			#region IdUsuarioSource
			if (CanDeepSave(entity, "Usuarios|IdUsuarioSource", deepSaveType, innerList) 
				&& entity.IdUsuarioSource != null)
			{
				DataRepository.UsuariosProvider.Save(transactionManager, entity.IdUsuarioSource);
				entity.IdUsuario = entity.IdUsuarioSource.IdUsuario;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region UsuariosRecursosChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>bookMaster.AssetSystem.Entities.UsuariosRecursos</c>
	///</summary>
	public enum UsuariosRecursosChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>Recursos</c> at IdRecursoSource
		///</summary>
		[ChildEntityType(typeof(Recursos))]
		Recursos,
			
		///<summary>
		/// Composite Property for <c>Usuarios</c> at IdUsuarioSource
		///</summary>
		[ChildEntityType(typeof(Usuarios))]
		Usuarios,
		}
	
	#endregion UsuariosRecursosChildEntityTypes
	
	#region UsuariosRecursosFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;UsuariosRecursosColumn&gt;"/> class
	/// that is used exclusively with a <see cref="UsuariosRecursos"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class UsuariosRecursosFilterBuilder : SqlFilterBuilder<UsuariosRecursosColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the UsuariosRecursosFilterBuilder class.
		/// </summary>
		public UsuariosRecursosFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the UsuariosRecursosFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public UsuariosRecursosFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the UsuariosRecursosFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public UsuariosRecursosFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion UsuariosRecursosFilterBuilder
	
	#region UsuariosRecursosParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;UsuariosRecursosColumn&gt;"/> class
	/// that is used exclusively with a <see cref="UsuariosRecursos"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class UsuariosRecursosParameterBuilder : ParameterizedSqlFilterBuilder<UsuariosRecursosColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the UsuariosRecursosParameterBuilder class.
		/// </summary>
		public UsuariosRecursosParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the UsuariosRecursosParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public UsuariosRecursosParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the UsuariosRecursosParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public UsuariosRecursosParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion UsuariosRecursosParameterBuilder
	
	#region UsuariosRecursosSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;UsuariosRecursosColumn&gt;"/> class
	/// that is used exclusively with a <see cref="UsuariosRecursos"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class UsuariosRecursosSortBuilder : SqlSortBuilder<UsuariosRecursosColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the UsuariosRecursosSqlSortBuilder class.
		/// </summary>
		public UsuariosRecursosSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion UsuariosRecursosSortBuilder
	
} // end namespace
